package org.example.demojdbc.repository;

import org.example.demojdbc.dox.Address;
import org.example.demojdbc.dox.User;
import org.example.demojdbc.dto.AddressUserDTO;
import org.example.demojdbc.mapper.AddressRowMapper;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AddressRepository extends CrudRepository<Address,String> {
    @Query("""
            select * from address a where a.user_id=:userId 
            """)
    List<Address> findByUserId(String userId);
    @Modifying
    @Query("update address a set a.detail=:detail where a.id=:id")
    void updateDetail(String detail,String id);
    @Query(value = "select * from user u,address a where u.id=a.user_id and a.id=:aid",rowMapperClass = AddressRowMapper.class)
    AddressUserDTO findByAId(String aid);
}
